package com.xian.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xian.common.annotation.Log;
import com.xian.common.core.controller.BaseController;
import com.xian.common.core.domain.AjaxResult;
import com.xian.common.enums.BusinessType;
import com.xian.manage.domain.Collections;
import com.xian.manage.service.ICollectionsService;
import com.xian.common.utils.poi.ExcelUtil;
import com.xian.common.core.page.TableDataInfo;

/**
 * 收藏管理Controller
 * 
 * @author Hanys
 * @date 2025-04-07
 */
@RestController
@RequestMapping("/manage/collections")
public class CollectionsController extends BaseController
{
    @Autowired
    private ICollectionsService collectionsService;

    /**
     * 查询收藏管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:collections:list')")
    @GetMapping("/list")
    public TableDataInfo list(Collections collections)
    {
        startPage();
        List<Collections> list = collectionsService.selectCollectionsList(collections);
        return getDataTable(list);
    }

    /**
     * 导出收藏管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:collections:export')")
    @Log(title = "收藏管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Collections collections)
    {
        List<Collections> list = collectionsService.selectCollectionsList(collections);
        ExcelUtil<Collections> util = new ExcelUtil<Collections>(Collections.class);
        util.exportExcel(response, list, "收藏管理数据");
    }

    /**
     * 获取收藏管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:collections:query')")
    @GetMapping(value = "/{collectionId}")
    public AjaxResult getInfo(@PathVariable("collectionId") Long collectionId)
    {
        return success(collectionsService.selectCollectionsByCollectionId(collectionId));
    }

    /**
     * 新增收藏管理
     */
    @PreAuthorize("@ss.hasPermi('manage:collections:add')")
    @Log(title = "收藏管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Collections collections)
    {
        return toAjax(collectionsService.insertCollections(collections));
    }

    /**
     * 修改收藏管理
     */
    @PreAuthorize("@ss.hasPermi('manage:collections:edit')")
    @Log(title = "收藏管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Collections collections)
    {
        return toAjax(collectionsService.updateCollections(collections));
    }

    /**
     * 删除收藏管理
     */
    @PreAuthorize("@ss.hasPermi('manage:collections:remove')")
    @Log(title = "收藏管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{collectionIds}")
    public AjaxResult remove(@PathVariable Long[] collectionIds)
    {
        return toAjax(collectionsService.deleteCollectionsByCollectionIds(collectionIds));
    }
}
